package com.learn.hibernatevalidator.chapter12.constraintapi;

import org.hibernate.validator.cfg.defs.AssertTrueDef;
import org.hibernate.validator.cfg.defs.MinDef;
import org.hibernate.validator.cfg.defs.NotNullDef;
import org.hibernate.validator.spi.cfg.ConstraintMappingContributor;

/**
 * @author: liyf
 * @create: 2025-01-25 19:22
 **/
public class MyConstraintMappingContributor implements ConstraintMappingContributor {

    @Override
    public void createConstraintMappings(ConstraintMappingBuilder builder) {
        builder.addConstraintMapping()
                .type(Marathon.class)
                .getter("name")
                .constraint(new NotNullDef())
                .field("numberOfHelpers")
                .constraint(new MinDef().value(1));

        builder.addConstraintMapping()
                .type(Runner.class)
                .field("paidEntryFee")
                .constraint(new AssertTrueDef());
    }
}